fix: preserve non-nil omitempty struct pointers - #601
Open
Boulea7 wants to merge 2 commits into
Open
Conversation
Change-Id: I9f2b3d140fd5e0bd3a757758a90271ddf2540068
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #503.
Summary
The
OpStructPtrHeadOmitEmptyVM path dereferenced a struct pointer and then fell through to the struct-value omit-empty path. That path could interpret a zero-valued first child field as a nil pointer and omit the entire non-nil child.This change keeps pointer traversal and nil checks at the correct indirection depth in the VM template, then regenerates all four VM variants (
vm,vm_color,vm_indent, andvm_color_indent). For direct-interface root structs, the compiler consumes exactly the pointer layer already held in the interface word, preserves additional pointer depth and recursive layouts, and bases recursion checks only on encoded fields. The regression matrix covers zero-valued first fields, nil and multi-level pointers, nested and sibling fields, pointer-valued child fields, ignored markers and back-references, and recursive roots across plain, colorized, indented, and colorized-indented output.Testing
go test . -run '^TestIssue503$' -count=100with Go 1.21.13go test . -run '^TestIssue503$' -count=10with Go 1.19.13 and 1.20.14go test ./... -count=1with Go 1.19.13, 1.20.14, and 1.21.13go test -race ./... -count=1with Go 1.21.13go generate ./internal/...with no generated diffgolangci-lint v1.54.2 run --timeout=5mgo vet ./...reports exactly the same existing diagnostics asmaster